package com.fdb.efp.flow.service.impl;

import java.util.List;
import java.util.Objects;

import com.fdb.efp.flow.service.dao.BizFlowParamDao;
import com.fdb.efp.flow.service.facade.BizFlowParamService;
import com.fdb.efp.flow.service.vo.BizFlowParamVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fdb.efp.flow.service.domain.BizFlowParam;
import com.fdb.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 业务流转参数				<p>
 * @author ligm
 * @date 2018-05-05
 */
@Service("bizFlowParamService")
public class BizFlowParamServiceImpl implements BizFlowParamService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(BizFlowParamServiceImpl.class);

	@Autowired
	private BizFlowParamDao bizFlowParamDao;
	
	/**
	 * 新增操作
	 */
	public int insertBizFlowParam(BizFlowParamVO inBizFlowParamVo) {
		logger.debug("当前新增数据为:"+ inBizFlowParamVo.toString());
		int num = 0;
		try {
			BizFlowParam bizFlowParam = new BizFlowParam();
			beanCopy(inBizFlowParamVo, bizFlowParam);
			num = bizFlowParamDao.insertBizFlowParam(bizFlowParam);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(BizFlowParamVO inBizFlowParamVo) {
		logger.debug("当前删除数据条件为:"+ inBizFlowParamVo);
		int num = 0;
		try {
			BizFlowParam bizFlowParam = new BizFlowParam();
			beanCopy(inBizFlowParamVo, bizFlowParam);
			num = bizFlowParamDao.deleteByPk(bizFlowParam);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inBizFlowParamVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(BizFlowParamVO inBizFlowParamVo) {
		logger.debug("当前修改数据为:"+ inBizFlowParamVo.toString());
		int num = 0;
		try {
			BizFlowParam bizFlowParam = new BizFlowParam();
			beanCopy(inBizFlowParamVo, bizFlowParam);
			num = bizFlowParamDao.updateByPk(bizFlowParam);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inBizFlowParamVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public BizFlowParamVO queryByPk(BizFlowParamVO inBizFlowParamVo) {
		
		logger.debug("当前查询参数信息为:"+ inBizFlowParamVo);
		try {
			BizFlowParam queryBizFlowParam = new BizFlowParam();
			beanCopy(inBizFlowParamVo, queryBizFlowParam);
			BizFlowParam queryRslBizFlowParam = bizFlowParamDao.queryByPk(queryBizFlowParam);
			if (Objects.nonNull(queryRslBizFlowParam)) {
				BizFlowParamVO outBizFlowParamVo = beanCopy(queryRslBizFlowParam, new BizFlowParamVO());
				logger.debug("当前查询结果为:"+ outBizFlowParamVo.toString());
				return outBizFlowParamVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BizFlowParamVO> queryAllOwner(BizFlowParamVO bizFlowParamVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<BizFlowParamVO> list = null;
		try {
			List<BizFlowParam> bizFlowParams = bizFlowParamDao.queryAllOwnerByPage(bizFlowParamVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ bizFlowParams.size());
			pageSet(bizFlowParams, bizFlowParamVo);
			list = (List<BizFlowParamVO>) beansCopy(bizFlowParams, BizFlowParamVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BizFlowParamVO> queryAllCurrOrg(BizFlowParamVO bizFlowParamVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<BizFlowParam> bizFlowParams = bizFlowParamDao.queryAllCurrOrgByPage(bizFlowParamVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+bizFlowParams.size());
		List<BizFlowParamVO> list = null;
		try {
			pageSet(bizFlowParams, bizFlowParamVo);
			list = (List<BizFlowParamVO>) beansCopy(bizFlowParams, BizFlowParamVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BizFlowParamVO> queryAllCurrDownOrg(BizFlowParamVO bizFlowParamVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<BizFlowParam> bizFlowParams = bizFlowParamDao.queryAllCurrDownOrgByPage(bizFlowParamVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ bizFlowParams.size());
		List<BizFlowParamVO> list = null;
		try {
			pageSet(bizFlowParams, bizFlowParamVo);
			list = (List<BizFlowParamVO>) beansCopy(bizFlowParams, BizFlowParamVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
